#!/usr/bin/python3
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: t -*-

import sys
import mrget
import subprocess
import mirrors.plugin


def main():
    dataDir = mirrors.plugin.params["storage-file"]["data-directory"]

    rsyncSource = None
    if True:
        urlList = mrget.target_urls("mirror://gentoo", protocols=["rsync"])
        if len(urlList) == 0:
            print("no update source found", file=sys.stderr)
            sys.exit(1)
        rsyncSource = urlList[0]

    print("Update from %s" % (rsyncSource))
    rc = subprocess.call(["rsync", "-v", "-a", "-z", "--delete", rsyncSource, dataDir])
    sys.exit(rc)


if __name__ == "__main__":
    main()
